<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="utf-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, user-scalable=no"/>
        <title>东航js日历公共demo--开发者，林露</title>
        <script type="text/javascript" src="src/script/libs/jquery-2.2.3.min.js"></script>
        <script type="text/javascript" src="src/script/plugins/datepicker.min.js"></script>
        <link rel="stylesheet" href="src/css/datepicker.css" type="text/css"/>

    </head>
    <body>
        <div id="mobileDate"></div>
        <div id="pcDate">
            <button type="button" name="button" id="J_back">返回上一页</button>
        </div>
        <script type="text/javascript">

            //获取浏览器参数
            function parse_url(url) {
                var pattern = /(\w+)=([^\#&]*)/ig;
                var parames = {};
                url.replace(pattern, function(attr, key, value) {
                    parames[key] = decodeURI(value);
                });
                return parames;
            };

            var Url = parse_url(window.location.href);
            if (Url.date) {
                var options = {
                    isDateAjax: true,
                    nowDate: new Date(),
                    dateData: Url.date.split(","),
                    dateConversion: function(e) {
                        var month = new Date(e).getMonth() + 1,
                            date = new Date(e).getDate();
                        if (month < 10) {
                            month = "0" + month;
                        };
                        if (date < 10) {
                            date = "0" + date;
                        };
                        return new Date(e).getFullYear() + '-' + month + '-' + date;
                    },
                    getNowDatePrice: function(e) {
                        var nowDate = options.dateConversion(e);
                        console.log(nowDate)
                        for (var i = 0; i < options.dateData.length; i++) {
                            if (options.dateData[i] == nowDate) {
                                return options.dateData[i];
                            }
                        }
                    }
                }
                /*
			 功能：手机端日历调用方法
			 开发者：林露
			 * */

                function getMobileDate() {
                    $('#mobileDate').DatePicker({
                        flat: true,
                        date: [
                            '2016-06-09', ''
                        ],
                        calendars: 1, //日历数量
                        mode: '', //模式，区域段选择还是单选
                        starts: 0,
                        current: Url.date.split(",")[0],
                        wrapClass: "priceWrap mobileDate",
                        onRender: function(date) {
                            var price = options.getNowDatePrice(date);
                            return {
                                disabled: (price == null
                                    ? true
                                    : false),
                                className: "dateTxt",
                                price: "可选"
                            }
                        },
                        onChange: function(formated, dates) { //日历选择回调事件
                            console.log(formated);
                            localStorage.setItem("selectDate", formated);
                            window.history.go(-1);
                        },
                        onChangeYear: function(date) {
                            options.startDate = "2016-0" + (new Date(date).getMonth() + 1)
                            options.isDateAjax = true;
                        }
                    })
                };
                getMobileDate();
            } else {}

            $('#J_back').on('click', function() {
                window.history.go(-1);
            })
        </script>
    </body>
</html>
